package order.demo.util;

import org.apache.ibatis.session.SqlSession;

import order.demo.mybatis.pojo.User;

public class AppTest {
	
	public static void main(String[] args) {
		User user = new User();
		user.setLoginName("123");
		user.setPassword("123");
		user.setNickname("123");
		user.setEmail("123");
		addNewUser(user);		
	}
	
	
	public static void addNewUser(User user) {
		SqlSession session = null;
		try {
			session = MybatisSessionUtil.getInstance().openSession();
			String st = "order.demo.mybatis.mapper.UserMapper.addNewUser";
			session.insert(st, user);
			session.commit();
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage(), e);
		} finally {
			closeSession(session);
		}
	}
	
	public static void closeSession(SqlSession session) {
		if(session != null) {
			session.close();
		}
	}

}
